package guoanmaker.operator.business.service;

import guoanmaker.operator.business.model.OperatorProvince;
import guoanmaker.operator.business.repository.OperatorProvinceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  
 *
 * @ClassName: OperatorProvinceService 
 * @Description: OperatorProvinceService 
 * @author: huZhaoyu 
 * @date 2017/6/28 下午2:56 
 */
@Service
public class OperatorProvinceService implements OperatorProvinceServiceInterface {
    private final OperatorProvinceRepository operatorProvinceRepository;

    @Override
    public Integer countAllById() {
        return operatorProvinceRepository.countAllByIdIsNotNull();
    }

    @Autowired
    public OperatorProvinceService(OperatorProvinceRepository operatorProvinceRepository) {
        this.operatorProvinceRepository = operatorProvinceRepository;
    }

    @Override
    public OperatorProvince saveProvince(OperatorProvince operatorProvince) {
        return operatorProvinceRepository.save(operatorProvince);
    }

    @Override
    public List<OperatorProvince> getAllProvince() {
        return operatorProvinceRepository.findAll();
    }

    @Override
    public Page<OperatorProvince> getAllProvinceByPage(Integer page, Integer size) {
        return operatorProvinceRepository.findAll(new PageRequest(page, size));
    }

    @Override
    public void deleteProvinceById(String id) {
        operatorProvinceRepository.delete(id);
    }

    @Override
    public OperatorProvince getProvinceById(String id) {
        return operatorProvinceRepository.findOne(id);
    }
}
